
/*
1、尽量以 pass-by-reference-to-const替换 pass-by-value。前者通常比较高效，并可避免切割问题(slicing problem)。
2、以上规则并不适用于内置类型，以及STL的迭代器和函数对象。对它们而言，pass-by-value往往比较适当。
*/



#include<iostream>

//考虑以下情形

//pass by value 花销::1次Person构造函数，1次Student copy构造函数，4次std::string 构造函数,总共6次的析构函数
                    //passs by reference const 花销：0
class Person
{
    public:
        Person(){std::cout<<"Person constructor"<<std::endl;};
        Person(const Person &p){std::cout<<"Person copy constructor"<<std::endl;};
        ~Person(){std::cout<<"Person destructor"<<std::endl;};
    private:
        std::string name;
        std::string address;
};

class Person1
{
    public:
        Person1(){std::cout<<"Person1 constructor"<<std::endl;};
        Person1(const Person &p){std::cout<<"Person1 copy constructor"<<std::endl;};
        ~Person1(){std::cout<<"Person1 destructor"<<std::endl;};
    private:
        std::string name;
        std::string address;
};

class Student:public Person
{
    public:
        Student(){std::cout<<"Student constructor"<<std::endl;};
        Student(const Student &p){std::cout<<"Student copy constructor"<<std::endl;};
        ~Student(){std::cout<<"Student destructor"<<std::endl;};
    private:
        std::string schoolName;
        std::string schoolAddress;
        Person1 p;
};

void checkStudent(const Student &s){};

int main(int argc, char const *argv[])
{
    Student s;
    checkStudent(s);//pass by value 花销::1次Person构造函数，1次Student copy构造函数，4次std::string 构造函数,总共6次的析构函数
                    //passs by reference const 花销：0
    return 0;
}
